package com.sample.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bdt.SampleBdt;
import com.framework.bdt.enumClass.DataSourceType;
import com.framework.stereotype.DataSource;
import com.sample.dao.SampleDao;
import com.sample.service.SampleService;

@DataSource(DataSourceType.SLAVE)			// DB 선택
@Transactional
@Service("SampleService")
public class SampleServiceImpl implements SampleService {

	private static final Logger log = LoggerFactory.getLogger(SampleServiceImpl.class);

	@Resource(name = "sampleDao")
	private SampleDao dao;

	@DataSource(DataSourceType.SLAVE)			// DB 선택
	@Transactional(readOnly=true)
	@Override
	public List<SampleBdt> getList() {
		List<SampleBdt> list = dao.getList();
		log.debug("result : {}", list);
		return list;
//		return dao.getList();
	}

	@Transactional(readOnly=true)
	@Override
	public SampleBdt getSample(int num) {
		SampleBdt bdt = dao.getSample(num);
		log.debug("result : {}", bdt);
		return bdt;
	}

	@Override
	public int insertSample(SampleBdt bdt) {
		return dao.insertSample(bdt);
	}


	@Override
	public int updateSample(SampleBdt bdt) {
		return dao.updateSample(bdt);
	}

	@Override
	public int deleteSample(int num) {
		return dao.deleteSample(num);
	}

	@Override
	public List<SampleBdt> setTranList(SampleBdt bdt) {
		log.debug("getTranList", bdt);
		dao.insertSample(bdt);
		bdt.setContent("내용 변경");
		log.debug("내용 변경", bdt);
		dao.updateSample(bdt);
		log.debug("에러");
		dao.insertSample(bdt);
		log.debug("실패");
		return dao.getList();
	}
}
